using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Models;
using FiltronASP.Models.DAO;
using FiltronASP.Models.DAO.Interfaces;

namespace FiltronASP.Helpers.LastSearches
{
    public class LastSearchesListHelper
    {
        public static string generatePaginatedLastSearchesList(int paginate, int languageId) {
            string strToRet = String.Empty;
            strToRet += String.Format("<h3 class=\"booked\">{0}</h3>", Helpers.Translations.translationHelper.getTranslation("_lastSearches", Convert.ToInt32(languageId)));
            ILastSearchesDAO lastSearchesDAO = new LastSearchesDAO();
            IQueryable<LastSearch> paginatedLSCollection = lastSearchesDAO.getLastSearchesPaginated(languageId, paginate);
            if (paginatedLSCollection.Any()) {
                List<LastSearch> lastSearchList = new List<LastSearch>();
                lastSearchList = paginatedLSCollection.ToList();
                for (int i = 0; i < 100; )
                {
                    strToRet += "<ul style=\"float: left;\">";
                    List<LastSearch> lastSearchListInLoop = lastSearchList.Skip(i).Take(20).ToList();
                    foreach (LastSearch singleLoop in lastSearchListInLoop)
                    {
                        strToRet += String.Format("<li><a href=\"{2}{1}\">{0}</a></li>",
                        singleLoop.last_search_name,
                        singleLoop.last_search_link,
                        Helpers.Translations.translationHelper.getTranslation("_lastSearchesLink", Convert.ToInt32(languageId)));
                    }
                    strToRet += "</ul>";
                    i += 20;
                }
            }
            if (paginate > 0) {
                strToRet += "<div onclick=\"lastSearchesList(" + (paginate - 1) + ", " + languageId + ");\" class=\"lastSearchListLeft\">&laquo;</div>";
            }

            IQueryable<LastSearch> paginatedLSCollectionNext = lastSearchesDAO.getLastSearchesPaginated(languageId, paginate + 1);
            List<LastSearch> lastSearchListNext = new List<LastSearch>();
            lastSearchListNext = paginatedLSCollectionNext.ToList();

            if (lastSearchListNext.Count == 100)
            {
                strToRet += "<div onclick=\"lastSearchesList(" + (paginate + 1) + ", " + languageId + ");\"class=\"lastSearchListRight\">&raquo;</div>";
            }
            return strToRet;
        }
    }
}
